// 获取图片容器和关闭按钮元素
var headerImage = document.getElementById("headerImage");
var closeButton = document.getElementById("closeButton");

// 页面加载完成后，展开图片
window.onload = function() {
    headerImage.style.height = "400px";
    setTimeout(hideImage, 5000); // 5秒后自动隐藏图片
};

// 点击按钮时，隐藏图片
function hideImage() {
    headerImage.style.height = "0";
}

// 回到顶部按钮
window.onscroll = function() {
    scrollFunction();
};

function scrollFunction() {
    if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
        document.getElementById("backToTopBtn").style.display = "block";
    } else {
        document.getElementById("backToTopBtn").style.display = "none";
    }
}

function scrollToTop() {
    window.scrollTo({ top: 0, behavior: 'smooth' });
}

// 轮播图逻辑
let slideIndex = 0;

function showSlides() {
    let slides = document.getElementsByClassName("carousel-item");
    for (let i = 0; i < slides.length; i++) {
        slides[i].classList.remove("active");
    }
    slideIndex++;
    if (slideIndex > slides.length) { slideIndex = 1 }
    slides[slideIndex - 1].classList.add("active");
    setTimeout(showSlides, 3000); // Change image every 3 seconds
}

function prevSlide() {
    let slides = document.getElementsByClassName("carousel-item");
    for (let i = 0; i < slides.length; i++) {
        slides[i].classList.remove("active");
    }
    slideIndex--;
    if (slideIndex < 1) { slideIndex = slides.length }
    slides[slideIndex - 1].classList.add("active");
}

function nextSlide() {
    let slides = document.getElementsByClassName("carousel-item");
    for (let i = 0; i < slides.length; i++) {
        slides[i].classList.remove("active");
    }
    slideIndex++;
    if (slideIndex > slides.length) { slideIndex = 1 }
    slides[slideIndex - 1].classList.add("active");
}

showSlides(); // Start the slideshow